package com.xbongbong.paas.help.business.rule.factory.impl;

import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.parent.condition.ProConditionHelp;
import com.xbongbong.parent.abstracts.AbstractConditionFieldHandler;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FilterConditionsPoJo;
import com.xbongbong.paas.field.LinkConditionPoJo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.businessrule.pojo.BusinessRuleInfoPojo;
import com.xbongbong.pro.condition.pojo.ConditionDTO;
import com.xbongbong.paas.field.LinkInfoPojo;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;


/**
 * 成员和部门处理
 * 注：此处主要是处理关联数据和数据联动多条件，业务规则的不会进
 *
 * @author: xingxing.xiao
 * @date: 2020/08/04 16:00
 */
@Component
public class ConditionFormLinkDataMultiHandlerImpl extends AbstractConditionFieldHandler {


    @Override
    public List<Integer> fieldType() {
        return Arrays.asList(FieldTypeEnum.LINK_DATA_MULTI.getType());
    }

    @Override
    public Object handlerFixedValue(FieldAttrEntity targetField, BusinessRuleInfoPojo businessRuleInfoPojo, FilterConditionsPoJo filterCondition) throws XbbException {
        // 关联多选不支持固定值条件
        return super.handlerFixedValue(targetField, businessRuleInfoPojo, filterCondition);
    }

    @Override
    public Object handlerPreConditionValue(FieldAttrEntity thisField, BusinessRuleInfoPojo businessRuleInfoPojo, FilterConditionsPoJo filterCondition) throws XbbException {
        // 关联多选作为阶段进入条件不支持固定值条件
        return handlerFixedValue(thisField, businessRuleInfoPojo, filterCondition);
    }

    @Override
    public Object handlerRelyFormField(String corpid, FieldAttrEntity fieldAttrEntity, FieldAttrEntity targetField, LinkConditionPoJo linkConditionPoJo, LinkInfoPojo linkInfoPojo, Object value) throws XbbException {
        // 关联数据多选作为关联数据的过滤条件
        return ProConditionHelp.getLinkDataMultiIdList(fieldAttrEntity, value);
    }

    @Override
    public Object handlerLinkDataFixedValue(String corpid, FieldAttrEntity targetField, LinkInfoPojo linkInfoPojo, Object value) throws XbbException {
        return value;
    }

    @Override
    public Object handlerBusinessRelyFormField(String corpid, FieldAttrEntity fieldAttrEntity, FieldAttrEntity targetField, LinkConditionPoJo linkConditionPoJo, Object value, Long linkFormId, Integer linkBusinessType, Integer linkSaasMark) throws XbbException {
        // 关联数据多选作为系统关联业务的过滤条件
        return handlerRelyFormField(corpid, fieldAttrEntity, targetField, linkConditionPoJo, null, value);
    }

    @Override
    public Object handlerBusinessDataFixedValue(String corpid, FieldAttrEntity targetField, ConditionDTO conditionDTO, Object value) throws XbbException {
        return value;
    }
}
